package com.shuoyue.ycgk.ui.mine.learnprogress.contract;

import com.shuoyue.ycgk.base.BaseModel;
import com.shuoyue.ycgk.base.BasePresenter;
import com.shuoyue.ycgk.base.BaseResult;
import com.shuoyue.ycgk.base.BaseView;
import com.shuoyue.ycgk.entity.LessonProcess;
import com.shuoyue.ycgk.net.RetrofitClient;
import com.shuoyue.ycgk.net.base.ApiSubscriber;
import com.shuoyue.ycgk.net.gsondefaultadapter.Optional;

import io.reactivex.Observable;

public interface FragmentLearnProcessContract {
    interface View extends BaseView {
        void setLessonProcess(LessonProcess lessonProcess);
    }

    class Presenter extends BasePresenter<View> {
        Model model = new Model();

        public void getProgressInfo(int subjectId ) {
            apply(model.getProgress(  subjectId  ))
                    .subscribe(new ApiSubscriber<Optional<LessonProcess>>(mView, this) {
                        @Override
                        public void onNext(Optional<LessonProcess> lessonProcessOptional) {
                            super.onNext(lessonProcessOptional);
                            mView.setLessonProcess(lessonProcessOptional.getIncludeNull());
                        }
                    });
        }
    }

    class Model extends BaseModel {
        Observable<BaseResult<LessonProcess>> getProgress(int moduleId ) {
            return RetrofitClient.getInstance().getApi().getLearnProcess(moduleId );
        }
    }

}
